package com.yupi.yuapidemo.controller;

import cn.hutool.json.JSONUtil;
import com.yupi.yuapicommon.model.entity.User;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


/**
 * @author zz_source
 * @creat 2023-01-08-22:45
 */
@RestController
@RequestMapping("/name")
public class NameController {

    @PostMapping("/get")
    public String getNameByGet(String name,HttpServletRequest request){
        System.out.println(request.getHeader("source"));
        return "Get 你的名字是" + name;
    }

    @PostMapping("/post")
    public String getNameByPost(@RequestBody String name){
        System.out.println("Post is ok!!");
        return "Post 你的名字是" + name;
    }

    @PostMapping("/user")
    public String getUsernameByPost(@RequestBody User user, HttpServletRequest request){
        String result = "Post 用户的名字是" + user.getUserName();
        return JSONUtil.toJsonStr(user);
    }
}
